package com.qf.flash.mvp.presenter;

import com.qf.dblib.dao.impl.UserMgr;
import com.qf.flash.http.HttpManager;
import com.qf.flash.http.response.BusinessInfoBean;
import com.qf.flash.mvp.contract.BusinessContract;
import com.qf.flashlib.base.BasePresenter;
import com.qf.flashlib.base.BaseResponse;
import com.qf.flashlib.base.BaseSubscriber;
import com.qf.flashlib.util.RxUtils;

import java.util.List;
import java.util.Map;

/**
 * 描述:商家选择
 * 2020/3/27 15:24
 */
public class BCPresenter extends BasePresenter<BusinessContract.View> implements BusinessContract.Presenter {
    @Override
    public void getBusinessList(Map<String, Object> map) {
        String uid = UserMgr.getInstance().getLoginUser().getUid();
        addSubscription(HttpManager.getInstance().getGsonHttpApi()
                .BUSINESS_LIST(map)
                .compose(RxUtils.handleBaseResult())
                .compose(RxUtils.io_main())
                .subscribeWith(new BaseSubscriber<BaseResponse<List<BusinessInfoBean>>>(mRootView) {
                    @Override
                    public void onSuccess(BaseResponse<List<BusinessInfoBean>> response) {
                        mRootView.setBusinessData(response.getData(),response.getTotalPage());
                    }
                })
        );
    }

    @Override
    public void choseBusiness(String orderId, String ShopId) {
        String uid = UserMgr.getInstance().getLoginUser().getUid();
        addSubscription(HttpManager.getInstance().getGsonHttpApi()
                .CHOSE_BUSINESS(uid, orderId, ShopId)
                .compose(RxUtils.handleBaseResult())
                .compose(RxUtils.io_main())
                .subscribeWith(new BaseSubscriber<BaseResponse<Object>>(mRootView) {
                    @Override
                    public void onSuccess(BaseResponse<Object> obj) {
                        mRootView.choseSuccess();
                    }
                })
        );
    }
}
